package com.april.pattern.creational.singleton;

/**
 * @author April
 * @version V1.0.0
 * @date 2019/06/23 09:25
 * @description 多线程获得单例实例
 */
public class ObtainInstance implements Runnable {
    @Override
    public void run() {
        /// 懒加载模式
        // LazySingleton instance = LazySingleton.getInstance();

        /// 双重检测锁模式
        // LazyDoubleCheckSingleton instance = LazyDoubleCheckSingleton.getInstance();

        /// 静态内部类模式
        // StaticInnerClassSingleton instance = StaticInnerClassSingleton.getInstance();

        // 饿汉式模式
        // HungrySingleton instance = HungrySingleton.getInstance();

        // 枚举单例模式
        // EnumInstance instance = EnumInstance.getInstance();

        // 容器单例
        /*ContainerSingleton.putInstance("object", new Object());
        Object instance = ContainerSingleton.getInstance("object");*/

        // 线程单例
        ThreadLocalInstance instance = ThreadLocalInstance.getInstance();

        System.out.println(Thread.currentThread().getName() + "===" + instance);
    }
}
